package stateDiagram.figures;

import static org.jhotdraw.draw.AttributeKeys.FILL_COLOR;
import static org.jhotdraw.draw.AttributeKeys.STROKE_COLOR;

import java.awt.Color;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;

import org.jhotdraw.draw.EllipseFigure;
import org.jhotdraw.draw.Figure;
import org.jhotdraw.draw.GraphicalCompositeFigure;
import org.jhotdraw.draw.connector.LocatorConnector;
import org.jhotdraw.draw.handle.BoundsOutlineHandle;
import org.jhotdraw.draw.handle.ConnectorHandle;
import org.jhotdraw.draw.handle.Handle;
import org.jhotdraw.draw.handle.MoveHandle;
import org.jhotdraw.draw.locator.RelativeLocator;
import org.jhotdraw.xml.DOMInput;
import org.jhotdraw.xml.DOMOutput;


import stateDiagram.EntityObjects.StateEntity;
import stateDiagram.EntityObjects.TransitionEntity;

public class StartStateFigure extends EllipseFigure{
	private StateEntity stateEntity;
	
	public StartStateFigure(){
		super();
		//EllipseFigure start = new EllipseFigure();
		stateEntity = new StateEntity("startState","empty", "empty");
		 setAttributeEnabled(FILL_COLOR, true);
		set(FILL_COLOR, Color.BLACK);
		
	}
	
	public StateEntity getStateEntity(){
		return stateEntity;
	}
	
    public void setBounds(Point2D.Double anchor, Point2D.Double lead) {
    	super.setBounds(anchor,new Point2D.Double( anchor.x +16, anchor.y +16));	
    	
    }
    
    public Collection<Handle> createHandles(int detailLevel) {
        java.util.List<Handle> handles = new LinkedList<Handle>();
        switch (detailLevel) {
            case -1:
               // handles.add(new BoundsOutlineHandle(getPresentationFigure(), false, true));
                break;
            case 0:
                handles.add(new MoveHandle(this, RelativeLocator.northWest()));
                handles.add(new MoveHandle(this, RelativeLocator.northEast()));
                handles.add(new MoveHandle(this, RelativeLocator.southWest()));
                handles.add(new MoveHandle(this, RelativeLocator.southEast()));
                ConnectorHandle ch;
               handles.add(ch = new ConnectorHandle(new LocatorConnector(this, RelativeLocator.east()), new TransitionFigure()));
                ch.setToolTipText("Drag the connector to the next State.");
                break;
        }
        return handles;
    }
    
    public void read(DOMInput in) throws IOException {
   	 double x = in.getAttribute("x", 0d);
        double y = in.getAttribute("y", 0d);
        //double w = in.getAttribute("w", 0d);
       // double h = in.getAttribute("h", 0d);
        setBounds(new Point2D.Double(x, y), new Point2D.Double(x + 16, y + 16));
        readAttributes(in);
   }

   @Override
   public void write(DOMOutput out) throws IOException {
   	 Rectangle2D.Double r = getBounds();
       out.addAttribute("x", r.x);
       out.addAttribute("y", r.y );
       writeAttributes(out);
    
     
   }


}
